import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/Layout'
import Search from '@/views/Search'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: () => import('@/views/Login')
    // 路由懒加载：webpack提供import函数，可以在路由路径匹配后，再去引入对应的组件
  },
  {
    path: '/layout',
    component: Layout,
    redirect: 'layout/home', // 立刻重定向
    children: [
      {
        path: 'home',
        component: () => import('@/views/Home')
      },
      {
        path: 'user',
        component: () => import('@/views/User')
      }
    ]
  },
  {
    path: '/search',
    component: Search
  },
  {
    path: '/search/:keywords',
    component: () => import('@/views/Search/SearchResult.vue')
  },
  {
    path: '/article_detail',
    component: () => import('@/views/ArticleDetail')
  },
  {
    path: '/user_edit',
    component: () => import('@/views/User/UserEdit')
  }
]

const router = new VueRouter({
  routes
})

export default router
